// import './assets/main.css'

import { createApp, provide } from 'vue'
import { createPinia } from 'pinia'
import { renderWithQiankun, qiankunWindow, type QiankunProps,  } from 'vite-plugin-qiankun/dist/helper'
import App from './App.vue'
import router from './router'

const app = createApp(App)

const render = (app:any, container?:any) => {
  app.mount(container ? container.querySelector("#app") : "#app");
};
const initQianKun = (app:any) => {
  renderWithQiankun({
    mount(props) {
      // 子应用接受主应用的参数
      props.onGlobalStateChange((val:any)=>{
        console.log('val来自主应用的参数', val);
      },true)
      const { container } = props
      render(app, container)
    },
    bootstrap() {
      console.log("bootstrap")
    },
    unmount() {
      console.log('子应用卸载');
      app.unmount()
    },
    update: function (props: QiankunProps): void | Promise<void> {
      throw new Error('Function not implemented.')
    }
  });
};
app.use(createPinia())
app.use(router)
// 初始化，判断是否在子应用的环境中
if( qiankunWindow.__POWERED_BY_QIANKUN__){
  initQianKun(app)
}else{
  render(app)
}
